<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
    <!-- <p>有时候我们需要父组件直接访问子组件，或者子组件直接访问父组件、根组件</p>
    <p>父组件访问子组件：使用$children或者$refs (reference引用)</p>
    <p>子组件访问父组件：使用$parent</p> -->
    <div id="app">
      
        <cpn></cpn>
    </div>
    <template id="cpn">
        <div>
         <h2>我是子组件</h2>
         <button @click="btnClick">按钮</button>
        </div>
    </template>
    <script>
        const app = new Vue({
            el: "#app",
            data: {
                message: "你好啊"
            },
        
            components: {
                cpn: {
                    template: "#cpn",
                    methods: {
                        btnClick() {
                        //访问父组件
                        console.log(this.$parent)
                        }
                        //访问根组件$root
                    }
                    
                }
               
                
            }
        })
    </script>
</body>
</html>